{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8c918eb5-8439-45f6-ac6b-f8342bd2fd71",
   "metadata": {},
   "source": [
    "确保第一件事，就是咱们要用的库已经安装好了"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "6cb5d836-7e22-42a2-b575-c79da278f75c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9f4ca2e6-e63f-4f98-bdc2-3992aa4154a3",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate list (not \"int\") to list",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[3], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m array \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m5\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m array \u001b[38;5;241m+\u001b[39m \u001b[38;5;241m1\u001b[39m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate list (not \"int\") to list"
     ]
    }
   ],
   "source": [
    "array = [1,2,3,4,5]\n",
    "array + 1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3276eec1-5c7a-4dbc-83c1-d70df7bdc134",
   "metadata": {},
   "source": [
    "直接对 数组 array + 1 是不能行的，可以使用np库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "389837a1-3773-4022-9732-6f54f76c96c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'>\n"
     ]
    }
   ],
   "source": [
    "array = np.array([1,2,3,4,5])\n",
    "print(type(array))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "f7a43922-1d47-4794-9ad2-1ebc551158ad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2, 3, 4, 5, 6])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 = array + 1\n",
    "array2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "409dbb0b-7dc3-43b4-b646-8b5040da3c91",
   "metadata": {},
   "source": [
    "##对 np.array 数组 +1，就是将其中的所有元素+1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5277e9a3-7308-454c-b012-6b0578d82d7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 3,  5,  7,  9, 11])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 + array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "9b8d9106-aa65-4e01-a703-37867ca22e0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2,  6, 12, 20, 30])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array2 * array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "c922057d-a2c4-49a8-a6f6-b17e9db2ef72",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "bfb6ee03-e8b9-4fa8-91a4-fa25844c1ed7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array[3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "b54a9d3c-b2dc-476f-aec2-9bb43ed0a37e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3, 4, 5])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "deb715af-04d8-4a80-a4f8-39f3e4694f6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(5,)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "array.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "a27919a3-0003-473e-9155-0cf9b944e04f",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'list' object has no attribute 'shape'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[30], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m tang_list \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m1\u001b[39m,\u001b[38;5;241m2\u001b[39m,\u001b[38;5;241m3\u001b[39m,\u001b[38;5;241m4\u001b[39m,\u001b[38;5;241m5\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m tang_list\u001b[38;5;241m.\u001b[39mshape\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'shape'"
     ]
    }
   ],
   "source": [
    "tang_list = [1,2,3,4,5]\n",
    "tang_list.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "0096666f-fe9d-40ef-92d6-f9465e3b347a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [2, 3, 4]])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.array([[1,2,3], [2,3,4]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3902c520-6511-4dd1-a18a-6d472fc18783",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
